<?php
class Pms extends Public_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->template->set_theme('tpso1');
		$this->template->set_layout('pms');
	}
	
	function index(){
		$this->template->set_layout('pms_index');
		$this->template->build('vdo_index2');
	}
	
	function content($content_type=FALSE,$province_name=FALSE,$district_name = FALSE){					
		switch($content_type):
			case 'objective':
				$data['pm'] = new Pm(1);
				$data['content_title'] = 'วัตถุประสงค์/แนวคิดบทบาทหน้าที่';
				$data['content'] = $data['pm']->detail;
				$data['id'] = $data['pm']->id;
				break;
			case 'step':
				$data['pm'] = new Pm(2);
				$data['content_title'] = 'ขั้นตอนการเสริมสร้าง';
				$data['content'] = $data['pm']->detail;
				$data['id'] = $data['pm']->id;
				break;
			case 'rules':
				$data['pm'] = new Pm(3);
				$data['content_title'] = 'ระเบียบข้อบังคับ';
				$data['content'] = $data['pm']->detail;
				$data['id'] = $data['pm']->id;
				break;
			case 'pstep':
				$data['pm'] = new Pm(5);
				$data['content_title'] = 'ขั้นตอน';
				$data['content'] = $data['pm']->detail;
				$data['id'] = $data['pm']->id;
				break;
			case 'pform':
				$data['pm'] = new Pm(6);
				$data['content_title'] = 'แบบฟอร์ม';
				$data['content'] = $data['pm']->detail;
				$data['id'] = $data['pm']->id;
				break;
			case 'pprivilege':
				$data['pm'] = new Pm(7);
				$data['content_title'] = 'สิทธิประโยชน์';
				$data['content'] = $data['pm']->detail;
				$data['id'] = $data['pm']->id;
				break;
			case 'download':
				$data['pm'] = new Pm(8);
				$data['content_title'] = 'ดาวน์โหลดเอกสาร ';
				$data['content'] = $data['pm']->detail;
				$data['id'] = $data['pm']->id;
				break;
			case 'province':
				$network_province = new Pm_network_province();
				$network_province->where("province_name ='".$province_name."' and district_name='' ")->get();
				$data['network_province'] = $network_province;
				$data['content_title'] = 'เครือข่ายพม. จังหวัด'.$network_province->province_name;								
				$data['content'] = $network_province->detail;
			break;
			case 'district':
				$network_province = new Pm_network_province();
				$network_province->where("province_name ='".$province_name."' and district_name ='".$district_name."' ")->get();
				$data['network_province'] = $network_province;
				$data['content_title'] = 'เครือข่ายพม. จังหวัด'.$network_province->province_name." อำเภอ".$network_province->district_name;								
				$data['content'] = $network_province->detail;
				break;
			default:
				$data['content_title'] = 'เครือข่ายพม.';
				$data['content'] = '';
				$data['vdos'] = new Vdo();				
					$data['categories'] = new Category();
					(@$_GET['albumsearch'])?$data['categories']->like('name',$_GET['albumsearch']):'';
					(@$_GET['groups'])?$data['categories']->where('group_id',$_GET['groups']):'';
					$data['categories']->where("module = 'vdos' and parents <> 0")->order_by('id','desc')->get_page();			    			 				
					$data['thumb_vdo'] = $data['vdos']->limit(4)->order_by("id","desc")->get();
					
				$data['informations'] = new Information();
				$data['informations']->where("pormor_show = 'yes' and status = 'approve'")->order_by("id","desc")->limit(6)->get();
				$data['infos'] = new Information();
				$data['infos']->where("tumbon_show = 'yes' and status = 'approve'")->limit(8,6)->order_by("id","desc")->get();
				
			break;
		endswitch;		
		if($content_type!=''){
			if($content_type != "province" && $content_type != "district"){
				$data['attachs'] = new Attach_file();
				$data['attachs']->where("content_id = ".$data['id']." and module = 'pms'")->get();
			}
		$this->template->build('index',$data);
		}else{
		$this->template->build('vdo_index',$data);
		}
	}	
	
	function inc_home(){
		$pm = new Pm_network_province();
		$nt_name = $pm->query("select distinct province_name from pms_network_province ")->where(" district_name = '' ")->get();
		//echo $pm->check_last_query();
		foreach($nt_name as $item):
			echo '<li><a href="pms/content/province/'.$item->province_name.'">จ.'.$item->province_name.'</a></li>';
		endforeach;
	}
	
	function download($id){
		$pm = new Pm($id);
		$pm->counter();
		$this->load->helper('download');
		$data = file_get_contents($pm->file);
		$name = basename($pm->file);
		force_download($name, $data); 
	}
	
	function gallery_list(){
		$data['categories'] = new Category();
		$data['categories']->where("start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'galleries' and parents <> 0 and status = 'approve' and pormor_show = 'yes'")->order_by('id','desc')->get();
		$this->template->build('gallery_index',$data);
	}

	function vdo_list(){
		$data['vdo_categories'] = new Category();
		$data['vdo_categories']->where("start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'vdos' and parents <> 0 and status = 'approve' and pormor_show = 'yes'")->order_by("id","desc")->get();
		$this->template->build('vdo_index',$data);
	}
	
	function view($id)
	{
		$data['catagory_id'] = $id;
		$data['galleries'] = new Gallery();
		$data['galleries']->where("category_id = '$id'")->order_by('orderlist','asc')->get_page();
		$this->template->build('gallery_view',$data);
	}
	
	function vdo($id){
		$data['vdos'] = new Vdo();
		$data['vdos']->where("category_id = ".$id)->order_by('id','desc')->get_page();
		$this->template->build('vdo_view',$data);
	}
	
	function information_list(){
		$data['informations'] = new Information();
		(@$_GET['titlesearch'])?$data['informations']->like('title',$_GET['titlesearch']):'';
		$data['informations']->where("pormor_show = 'yes'")->order_by("id","desc")->get_page();
		$this->template->build('informations_index',$data);
	}
}
?>